package com.example.smartall.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.example.smartall.R;
import com.example.smartall.entity.HospitalCategoryBean;
import com.example.smartall.fragment.Hospital.CommonFragment;
import com.example.smartall.ui.HRDetailsActivity;

import java.util.List;

/**
 * @author abbas
 * @brief description
 * @date 2022-01-29
 */
public class HospitalRegistrationAdapter extends BaseAdapter {

    private Context context;
    private List<CommonFragment.DataBean> beans;
    private HospitalCategoryBean.RowsBean categoryBeans;
    private String patientName;

    public HospitalRegistrationAdapter(Context context, List<CommonFragment.DataBean> beans,HospitalCategoryBean.RowsBean categoryBeans,String patientName) {
        this.context = context;
        this.beans = beans;
        this.categoryBeans = categoryBeans;
        this.patientName = patientName;
    }

    @Override
    public int getCount() {
        return beans.size();
    }

    @Override
    public Object getItem(int i) {
        return beans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.hospital_registration_item,null,false);
            viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tvType = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.btRegister = convertView.findViewById(R.id.bt_registration);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvTitle.setText(beans.get(i).getType());
        viewHolder.tvType.setText(beans.get(i).getWhen());
        viewHolder.tvTime.setText(beans.get(i).getDate() +" "+ beans.get(i).getTime());
        viewHolder.btRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //TODO
                Intent intent = new Intent(context, HRDetailsActivity.class);
                intent.putExtra("time",beans.get(i));
                intent.putExtra("data",categoryBeans);
                intent.putExtra("name",patientName);
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder {
        private TextView tvTitle;
        private TextView tvType;
        private TextView tvTime;
        private Button btRegister;
    }
}

